﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CenterSpace.NMath.Core;
using CenterSpace.NMath.Stats;

namespace WebAccess
{
    public abstract class ChoiceStats: StatEngine
    {
       public abstract  double Calculate(System.Collections.Generic.HashSet<SensorNetworkUI.SensorStructure> sensors, double value);
        protected ChoiceStats()
        {



        }
        public static ChoiceStats GetInstance(String type)
        {

            switch (type)
            {
                case "Rank":
                    return new Rank();
                case "Quartile":
                    return new Quartile();
                case "Percentile":
                    return new Percentile();
                case "PR":
                    return new PercentileRank();
                 default:
                    throw new NotImplementedException();


            }


        }


    }
    public class Rank : ChoiceStats
    {


        public override double Calculate(HashSet<SensorNetworkUI.SensorStructure> sensors, double value)
        {
            double[] vals = SetToArray(sensors);
            return StatsFunctions.Rank(vals, value);
            
        }
    }
    public class Quartile : ChoiceStats
    {

        public override double Calculate(HashSet<SensorNetworkUI.SensorStructure> sensors, double value)
        {
            double[] vals = SetToArray(sensors);
            return StatsFunctions.Quartile(vals, (int)value);
        }
    }
    public class PercentileRank : ChoiceStats
    {
        public override double Calculate(HashSet<SensorNetworkUI.SensorStructure> sensors, double value)
        {
            double[] vals = SetToArray(sensors);
            return StatsFunctions.PercentileRank(vals, value);

        }
    }
    public class Percentile : ChoiceStats
    {


        public override double Calculate(HashSet<SensorNetworkUI.SensorStructure> sensors, double value)
        {
            double[] vals = SetToArray(sensors);
            return StatsFunctions.Percentile(vals, value);
        }

    }
}